package com.yk.web.controller;

import java.util.List;

import com.yk.course.domain.CoursePeriod;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yk.common.annotation.Log;
import com.yk.common.enums.BusinessType;
import com.yk.course.service.ICoursePeriodService;
import com.yk.common.core.controller.BaseController;
import com.yk.common.core.domain.AjaxResult;
import com.yk.common.utils.poi.ExcelUtil;
import com.yk.common.core.page.TableDataInfo;

/**
 * 课程详情Controller
 * 
 * @author xufei
 * @date 2025-05-03
 */
@Controller
@RequestMapping("/course/coursePeriod")
public class CoursePeriodController extends BaseController
{
    private String prefix = "course/coursePeriod";

    @Autowired
    private ICoursePeriodService coursePeriodService;

    @RequiresPermissions("course:coursePeriod:view")
    @GetMapping()
    public String coursePeriod()
    {
        return prefix + "/coursePeriod";
    }

    /**
     * 查询课程详情列表
     */
    @RequiresPermissions("course:coursePeriod:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CoursePeriod coursePeriod)
    {
        startPage();
        List<CoursePeriod> list = coursePeriodService.selectCoursePeriodList(coursePeriod);
        return getDataTable(list);
    }

    /**
     * 导出课程详情列表
     */
    @RequiresPermissions("course:coursePeriod:export")
    @Log(title = "课程详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CoursePeriod coursePeriod)
    {
        List<CoursePeriod> list = coursePeriodService.selectCoursePeriodList(coursePeriod);
        ExcelUtil<CoursePeriod> util = new ExcelUtil<CoursePeriod>(CoursePeriod.class);
        return util.exportExcel(list, "课程详情数据");
    }

    /**
     * 新增课程详情
     */
    @RequiresPermissions("course:coursePeriod:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存课程详情
     */
    @RequiresPermissions("course:coursePeriod:add")
    @Log(title = "课程详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CoursePeriod coursePeriod)
    {
        return toAjax(coursePeriodService.insertCoursePeriod(coursePeriod));
    }

    /**
     * 修改课程详情
     */
    @RequiresPermissions("course:coursePeriod:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CoursePeriod coursePeriod = coursePeriodService.selectCoursePeriodById(id);
        mmap.put("coursePeriod", coursePeriod);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程详情
     */
    @RequiresPermissions("course:coursePeriod:edit")
    @Log(title = "课程详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CoursePeriod coursePeriod)
    {
        return toAjax(coursePeriodService.updateCoursePeriod(coursePeriod));
    }

    /**
     * 删除课程详情
     */
    @RequiresPermissions("course:coursePeriod:remove")
    @Log(title = "课程详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(coursePeriodService.deleteCoursePeriodByIds(ids));
    }
}
